<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<lv-form [formGroup]='formGroup'>
    <lv-form-item *ngIf="componentData.childResourceType && dataMap.Resource_Type.tdsqlInstance.value.includes(componentData.childResourceType[0])">
        <lv-form-label lvRequired>{{ "common_port_label" | i18n}}</lv-form-label>
        <lv-form-control [lvErrorTip]='mysqlPortErrorTip'>
            <input lv-input type='text' formControlName='mysql_port' class="script-input"/>
        </lv-form-control>
    </lv-form-item>
    <lv-form-item>
        <lv-form-label> {{ 'common_bindwidth_label' | i18n }}</lv-form-label>
        <lv-form-control>
            <lv-group lvDirection='vertical' lvGutter='8px'>
                <lv-switch formControlName='bindWidthStatus' class="mount-bindWidth"></lv-switch>
                <lv-group lvGutter='8px' *ngIf="formGroup.value.bindWidthStatus" class="lv-group-flex-start">
                    <lv-group lvDirection='vertical'>
                        <lv-form-label lvRequired>
                            <span class="aui-text-help-sm">
                                {{'explore_min_label' | i18n}}
                            </span>
                        </lv-form-label>
                        <lv-form-control [lvErrorTip]='minBandwidthErrorTip'>
                            <input lv-input type="text" formControlName="min_bandwidth" class="advanced-input-container"
                                placeholder="1~999999999" />
                        </lv-form-control>
                    </lv-group>
                    <lv-group lvDirection='vertical'>
                        <lv-form-label lvRequired>
                            <span class="aui-text-help-sm">
                                {{'explore_max_label' | i18n}}
                            </span>
                        </lv-form-label>
                        <lv-form-control [lvErrorTip]='maxBandwidthErrorTip'>
                            <input lv-input type="text" formControlName="max_bandwidth" class="advanced-input-container"
                                placeholder="1~999999999" />
                        </lv-form-control>
                    </lv-group>
                    <lv-group lvDirection='vertical'
                        *ngIf="formGroup.value.max_bandwidth && formGroup.get('max_bandwidth').valid">
                        <lv-form-label>
                            <span class="aui-text-help-sm">
                                {{'explore_burst_label' | i18n}}
                            </span>
                        </lv-form-label>
                        <lv-form-control [lvErrorTip]='burstBandwidthErrorTip'>
                            <input lv-input type="text" formControlName="burst_bandwidth"
                                class="advanced-input-container" placeholder="1~999999999" />
                        </lv-form-control>
                    </lv-group>
                    <lv-group lvDirection='vertical'>
                        <lv-form-label></lv-form-label>
                        MB/s
                    </lv-group>
                </lv-group>
            </lv-group>
        </lv-form-control>
    </lv-form-item>
    <lv-form-item>
        <lv-form-label> {{ 'protection_nor_iops_label' | i18n }}</lv-form-label>
        <lv-form-control>
            <lv-group lvDirection='vertical' lvGutter='8px'>
                <lv-group lvGutter='8px'>
                    <lv-switch formControlName='iopsStatus'></lv-switch>
                    <span class="aui-link" lv-popover [lvPopoverTrigger]="'hover'" [lvPopoverContent]="iopsContentTpl">
                        {{'common_more_label'|i18n}}
                    </span>
                </lv-group>
                <lv-group lvGutter='8px' *ngIf="formGroup.value.iopsStatus" class="lv-group-flex-start">
                    <lv-group lvDirection='vertical'>
                        <lv-form-label lvRequired>
                            <span class="aui-text-help-sm">
                                {{'explore_min_label' | i18n}}
                            </span>
                        </lv-form-label>
                        <lv-form-control [lvErrorTip]='minIopsErrorTip'>
                            <input lv-input type="text" formControlName="min_iops" class="advanced-input-container"
                                placeholder="100~999999999" />
                        </lv-form-control>
                    </lv-group>
                    <lv-group lvDirection='vertical'>
                        <lv-form-label lvRequired>
                            <span class="aui-text-help-sm">
                                {{'explore_max_label' | i18n}}
                            </span>
                        </lv-form-label>
                        <lv-form-control [lvErrorTip]='maxIopsErrorTip'>
                            <input lv-input type="text" formControlName="max_iops" class="advanced-input-container"
                                placeholder="100~999999999" />
                        </lv-form-control>
                    </lv-group>
                    <lv-group lvDirection='vertical'
                        *ngIf="formGroup.value.max_iops && formGroup.get('max_iops').valid">
                        <lv-form-label>
                            <span class="aui-text-help-sm">
                                {{'explore_burst_label' | i18n}}
                            </span>
                        </lv-form-label>
                        <lv-form-control [lvErrorTip]='burstIopsErrorTip'>
                            <input lv-input type="text" formControlName="burst_iops" class="advanced-input-container"
                                placeholder="100~999999999" />
                        </lv-form-control>
                    </lv-group>
                </lv-group>
            </lv-group>
        </lv-form-control>
    </lv-form-item>
    <ng-container
        *ngIf="(formGroup.value.iopsStatus && formGroup.value.burst_iops) || (formGroup.value.bindWidthStatus && formGroup.value.burst_bandwidth)">
        <lv-form-item>
            <lv-form-label lvRequired> {{'explore_max_burst_label' | i18n}}</lv-form-label>
            <lv-form-control [lvErrorTip]='burstTimeErrorTip'>
                <input lv-input type="text" formControlName="burst_time" class="advanced-input-container"
                    placeholder="1~999999999" />
                <i lv-icon="aui-icon-help" lv-tooltip="{{'explore_max_burst_desc_label' | i18n}}" lvTooltipTheme="light"
                    class="configform-constraint" lvColorState='true'></i>
            </lv-form-control>
        </lv-form-item>
    </ng-container>
    <lv-form-item>
        <lv-form-label> {{'protection_nor_latency_label' | i18n}}</lv-form-label>
        <lv-form-control>
            <lv-group lvDirection='vertical' lvGutter='8px'>
                <lv-group lvGutter='8px'>
                    <lv-switch formControlName='latencyStatus'></lv-switch>
                    <span class="aui-link" lv-popover [lvPopoverTrigger]="'hover'"
                        [lvPopoverContent]="latencyContentTpl">
                        {{'common_more_label'|i18n}}
                    </span>
                </lv-group>
                <lv-group lvGutter='8px' *ngIf="formGroup.value.latencyStatus">
                    <lv-group lvDirection='vertical'>
                        <lv-form-label lvRequired>
                            <span class="aui-text-help-sm">
                                {{'explore_max_label' | i18n}}
                            </span>
                        </lv-form-label>
                        <lv-form-control [lvErrorTip]="baseUtilService.requiredErrorTip">
                            <lv-select formControlName="latency" [lvOptions]='latencyOptions' lvValueKey='value'
                                class="advanced-input-container" lvShowClear>
                            </lv-select>
                        </lv-form-control>
                    </lv-group>
                </lv-group>
            </lv-group>
        </lv-form-control>
    </lv-form-item>
    <ng-container *ngIf="item.resource_sub_type === dataMap.Resource_Type.oracle.value">
        <lv-form-item>
            <lv-form-label>
                {{'explore_mount_pre_script_label' | i18n}}
            </lv-form-label>
            <lv-form-control [lvErrorTip]='scriptNameErrorTip'>
                <input lv-input type='text' formControlName='pre_script' class="script-input"
                    placeholder="{{'common_script_linux_placeholder_label'|i18n}}" />
                <i lv-icon="aui-icon-help" lv-tooltip="{{'common_script_agent_position_label' | i18n}}"
                    lvTooltipTheme="light" class="configform-constraint" lvColorState='true'></i>
            </lv-form-control>
        </lv-form-item>
        <lv-form-item>
            <lv-form-label>
                {{'explore_mount_success_script_label' | i18n}}
            </lv-form-label>
            <lv-form-control [lvErrorTip]='scriptNameErrorTip'>
                <input lv-input type='text' formControlName='post_script' class="script-input"
                    placeholder="{{'common_script_linux_placeholder_label'|i18n}}" />
                <i lv-icon="aui-icon-help" lv-tooltip="{{'common_script_agent_position_label' | i18n}}"
                    lvTooltipTheme="light" class="configform-constraint" lvColorState='true'></i>
            </lv-form-control>
        </lv-form-item>
        <lv-form-item>
            <lv-form-label>
                {{'explore_mount_fail_script_label' | i18n}}
            </lv-form-label>
            <lv-form-control [lvErrorTip]='scriptNameErrorTip'>
                <input lv-input type='text' formControlName='failed_script' class="script-input"
                    placeholder="{{'common_script_linux_placeholder_label'|i18n}}" />
                <i lv-icon="aui-icon-help" lv-tooltip="{{'common_script_agent_position_label' | i18n}}"
                    lvTooltipTheme="light" class="configform-constraint" lvColorState='true'></i>
            </lv-form-control>
        </lv-form-item>
    </ng-container>
    <ng-container
        *ngIf="![dataMap.Resource_Type.NASShare.value, dataMap.Resource_Type.NASFileSystem.value].includes(item.resource_sub_type)">
        <lv-form-item>
            <lv-form-label>
                {{'common_updating_policy_label' | i18n}}
            </lv-form-label>
            <lv-form-control>
                <lv-select formControlName="policyId" [lvOptions]='policyOptions' lvValueKey='key' lvShowClear
                    lvShowFilter lvFilterKey='label' lvFilterMode='contains'></lv-select>
            </lv-form-control>
        </lv-form-item>
    </ng-container>
</lv-form>

<ng-template #iopsContentTpl>
    <lv-group lvGutter='32px'>
        <lv-group lvDirection='vertical' lvGutter='16px'>
            <span class="aui-text-desc">{{'explore_io_size_label' | i18n}}</span>
            <span class="aui-text-desc">Min</span>
            <span class="aui-text-desc">Max</span>
            <span class="aui-text-desc">Burst</span>
        </lv-group>
        <lv-group *ngFor="let item of iopsItems" lvDirection='vertical' lvGutter='16px'>
            <span>{{item.header}}</span>
            <span>{{item.min | nil}}</span>
            <span>{{item.max | nil}}</span>
            <span>{{item.burst | nil}}</span>
        </lv-group>
    </lv-group>
</ng-template>

<ng-template #latencyContentTpl>
    <lv-group lvGutter='32px'>
        <lv-group lvDirection='vertical' lvGutter='16px'>
            <span class="aui-text-desc">{{'explore_io_size_label' | i18n}}</span>
            <span class="aui-text-desc">Max</span>
        </lv-group>
        <lv-group *ngFor="let item of latencyItems" lvDirection='vertical' lvGutter='16px'>
            <span>{{item.header}}</span>
            <span>{{item.max | nil}}</span>
        </lv-group>
    </lv-group>
</ng-template>